class PhoneAction extends egret.Sprite{
	private bmp:egret.Bitmap;
	private text_value0:egret.TextField;
	private text_value1:egret.TextField;
	private text_value2:egret.TextField;
	public static startAlpha;
	public static startBeta;
	public static startGamma;
	public static motion:egret.Motion;
	public static orient:egret.DeviceOrientation;
	private msg:Mediator=Mediator.getInstance();
	public constructor() {
		super();

	   this.bmp=new egret.Bitmap();
       this.bmp.texture=RES.getRes('创邑_LOGO_png');
       this.bmp.name='l';
       this.bmp.anchorOffsetX=this.bmp.width/2;
       this.bmp.x=740/2;
       this.bmp.y=310;
       this.addChild(this.bmp);

		this.text_value0=new egret.TextField();
		this.text_value0.size=20;
		this.text_value0.wordWrap=true;
		this.text_value0.textColor=0xff0000;
		this.text_value0.text='hahaha';
		this.addChild(this.text_value0);

		this.text_value1=new egret.TextField();
		this.text_value1.size=20;
		this.text_value1.wordWrap=true;
		this.text_value1.textColor=0xff0000;
		this.text_value1.text='hahaha';
		this.text_value1.y=40;
		this.addChild(this.text_value1);

		this.text_value2=new egret.TextField();
		this.text_value2.size=20;
		this.text_value2.wordWrap=true;
		this.text_value2.textColor=0xff0000;
		this.text_value2.text='hahaha';
		this.text_value2.y=80;
		this.addChild(this.text_value2);
		
		PhoneAction.orient=new egret.DeviceOrientation();
		PhoneAction.orient.addEventListener(egret.Event.CHANGE,this.orientHandler,this);

		PhoneAction.motion=new egret.Motion();
        PhoneAction.motion.addEventListener(egret.MotionEvent.CHANGE,this.motionHandler,this);
	}
	public static start()
	{
		// PhoneAction.motion.start();
		PhoneAction.orient.start();
	}
	public static stop()
	{
		// PhoneAction.motion.stop();
		PhoneAction.orient.stop();
	}
	private orientHandler(e:egret.OrientationEvent):void
    {
		var arr:Array<Number>=[Math.floor(e.alpha),Math.floor(e.beta),Math.floor(e.gamma)];
		try
		{
			this.text_value0.text='alpha:'+e.alpha.toString();
			this.text_value1.text='beta:'+e.beta.toString();
			this.text_value2.text='gamma:'+e.gamma.toString();
			this.msg.dispatchEvent(new MediatorEvent('PhoneAction_Orient',arr));
		}
		catch(e)
		{

		}
	}
	private motionHandler(e:egret.MotionEvent):void
    {
		var arr:Array<Number>=[Math.floor(e.rotationRate.alpha),Math.floor(e.rotationRate.beta),Math.floor(e.rotationRate.gamma)];
		try
		{
			this.text_value0.text='alpha:'+Math.floor(e.rotationRate.alpha).toString();
			this.text_value1.text='beta:'+Math.floor(e.rotationRate.beta).toString();
			this.text_value2.text='gamma:'+Math.floor(e.rotationRate.gamma).toString();
			this.msg.dispatchEvent(new MediatorEvent('PhoneAction_Motion',arr));
		}
		catch(e)
		{

		}
		
	}
}